package com.doubao.wechat.feign;

import com.doubao.common.result.Result;
import com.doubao.wechat.feign.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * UserFeignClient的本地实现，用于在无法连接用户服务时提供兜底功能
 */
@Component
@Slf4j
public class UserFeignClientImpl implements UserFeignClient {

    @Override
    public Result<UserDTO> getUserById(Long userId) {
        log.warn("本地实现被调用: getUserById({})", userId);
        
        // 创建一个简单的用户DTO作为兜底返回
        UserDTO userDTO = new UserDTO();
        userDTO.setId(userId);
        userDTO.setUsername("localUser");
        userDTO.setNickname("本地用户");
        userDTO.setMiniappOpenid("local_openid_miniapp");
        userDTO.setOfficialOpenid("local_openid_official");
        
        return Result.success(userDTO);
    }

    @Override
    public Result<Void> updateUserAvatar(Long userId, String avatarUrl) {
        log.warn("本地实现被调用: updateUserAvatar({}, {})", userId, avatarUrl);
        return Result.success();
    }

    @Override
    public Result<Boolean> checkUserExists(Long userId) {
        log.warn("本地实现被调用: checkUserExists({})", userId);
        // 兜底逻辑，假设用户存在
        return Result.success(true);
    }

    @Override
    public Result<String> getUserAvatar(Long userId) {
        log.warn("本地实现被调用: getUserAvatar({})", userId);
        // 返回一个默认的头像URL
        return Result.success("https://example.com/default-avatar.png");
    }
    
    @Override
    public Result<Void> bindUserWechatInfo(Long userId, String openid, String unionid) {
        log.warn("本地实现被调用: bindUserWechatInfo({}, {}, {})", userId, openid, unionid);
        return Result.success();
    }
    
    @Override
    public Result<Void> activateMembership(Long userId, Integer levelId, String subscriptionType, 
                                          Integer days, String source, String orderId) {
        log.warn("本地实现被调用: activateMembership({}, {}, {}, {}, {}, {})", 
                userId, levelId, subscriptionType, days, source, orderId);
        // 兜底逻辑，假设激活成功
        return Result.success();
    }
} 